<?php if (!defined('THINK_PATH')) exit();?><style>
    input.form-control{width:220px;border:1px solid rgb(204, 204, 204);padding:0 10px;height:30px;}
</style>

<ul class="nav nav-tabs" role="tablist">
    <li class="active" role="presentation"><a data-toggle="tab" href="#Process">流程设置</a></li>
</ul>
<div class="tab-content">
    <div role="tabpanel" id="Process" class="tab-pane active">
        <form id="AddProcess" class="form-horizontal" method="post" action="<?php echo U('Admin/Process/setting');?>">
            <input type="hidden" name="ID" value="<?php echo ($process["ID"]); ?>"/>
            <div class="control-group">
                <label for="Name" class="control-label">流程名称</label>
                <div class="controls">
                    <input type="text" disabled="disabled" class="form-control" name="Name" id="Name" value="<?php echo ($process["Name"]); ?>" placeholder="流程名称">
                </div>
            </div>
            <div class="control-group">
                <label for="BPType" class="control-label">流程类型</label>
                <div class="controls">
                    <select id="BPType" name="BPType" disabled="disabled" class="form-control">
                        <?php if(is_array($BPType)): foreach($BPType as $key=>$vo): $selected = $process['BPType']==$key?'selected':''; ?>
                            <option <?php echo ($selected); ?> value="<?php echo ($key); ?>"><?php echo ($vo); ?></option><?php endforeach; endif; ?>
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label for="HandleDpt" class="control-label">主办部门</label>
                <div class="controls">
                    <input type="hidden" class="form-control" value="<?php echo ($handleDepartment["ID"]); ?>" name="HandleDptID" id="HandleDptID" placeholder="主办部门">
                    <input style="cursor:pointer;background:url('./Public/Admin/img/Arrow-Icon.png') right center no-repeat" readonly="readonly" type="text" class="form-control selector-icon" value="<?php echo ($handleDepartment["Name"]); ?>" name="HandleDpt" id="HandleDpt" placeholder="主办部门">
                </div>
            </div>
            <div class="control-group">
                <label for="HandleUser" class="control-label">主办人</label>
                <div class="controls">
                    <input type="hidden" class="form-control" value="<?php echo ($handleUser["ID"]); ?>" name="HandleUserID" id="HandleUserID" placeholder="主办人">
                    <input style="cursor:pointer;background:url('./Public/Admin/img/Arrow-Icon.png') right center no-repeat" type="text" class="form-control" value="<?php echo ($handleUser["TrueName"]); ?>" name="HandleUser" id="HandleUser" placeholder="主办人">
                </div>
            </div>
            <div class="control-group">
                <label for="LimitTime" class="control-label">办理时限</label>
                <div class="controls">
                    <input id="LimitTime" name="LimitTime" type="text" value="<?php echo ($process["LimitTime"]); ?>" class="form-control"/> ( / 天)
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <button id="addBtn" type="button" class="btn btn-default">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>

    var memberSelector = new MemberSelector('#HandleDpt',{
        title : '选择部门',
        type : 2
    },function(itemList){
        var ids = '';
        var titles = '';
        for(var i = 0; i < itemList.length; i++){
            var id = itemList[i].id;
            var title = itemList[i].title;
            ids += id;
            ids += (i+1 == itemList.length)?'':',';
            titles += title;
            titles += (i+1 == itemList.length)?'':',';
        }
        $('input[name=HandleDptID]').val(ids);
        $('input[name=HandleDpt]').val(titles);

        console.log(itemList);
    });
    var memberSelector2 = new MemberSelector('#HandleUser',{
        title : '选择人员',
        type : 1
    },function(itemList){
        var ids = '';
        var titles = '';
        for(var i = 0; i < itemList.length; i++){
            var id = itemList[i].id;
            var title = itemList[i].title;
            ids += id;
            ids += (i+1 == itemList.length)?'':',';
            titles += title;
            titles += (i+1 == itemList.length)?'':',';
        }
        $('input[name=HandleUserID]').val(ids);
        $('input[name=HandleUser]').val(titles);

        console.log(itemList);
    });

    //保存流程
    $('button#addBtn').click(function(){

        var data = {};
        data['ID'] = $('input[name=ID]').val();
        //data['Name'] = $.trim($('input[name=Name]').val());
        //data['BPType'] = $('select[name=BPType]').val();
        data['HandleDptID'] = $('input[name=HandleDptID]').val();
        data['HandleUserID'] = $('input[name=HandleUserID]').val();
        data['LimitTime'] = $('input[name=LimitTime]').val();

        console.log(data);
        var url = $('form#AddProcess').attr('action');
        $.ajax({
            url : url,
            type : 'post',
            dataType : 'json',
            data : {
                data : data
            },
            success : function(data){
                console.log(data);
                if(data.status===1){
                    alert('保存成功');
                }
            },
            error : function(data){
                console.log(data);
            }
        });
    });

</script>